package com.irdstudio.bhcredit.core.assembly.plugin.webapp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * 数据表操作类-[表名: 01.WAS调用组包配置表(urps.plugin_webapp_conf)]
 * 通过JDBC实现基本的数据表操作(CRUD) 
 * @author 代码自动生成
 * @version 1.0
 * @date 2013-10-25
 */
public class PluginWebappConfDao {

	/* 连接对象 */
	Connection conn = null;	

	public PluginWebappConfDao(Connection conn){
		this.conn = conn;
	}

	/**
	 * 根据主键查询单条记录
	 * @param 
	 * @return
	 * @throws SQLException
	 */
	public PluginWebappConf queryPluginWebappConfWithKeys(String pluginConfId,int confSort)
			throws SQLException {
		PluginWebappConf dc = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn
					.prepareStatement("SELECT * FROM urps.plugin_webapp_conf WHERE plugin_conf_id=?,conf_sort=? with ur");
			ps.setString(1,pluginConfId);
			ps.setInt(2,confSort);
			rs = ps.executeQuery();
			if (rs.next()) {
				dc = new PluginWebappConf();
				dc.setPluginConfId(rs.getString("plugin_conf_id"));
				dc.setConfSort(rs.getInt("conf_sort"));
				dc.setWsAddr(rs.getString("ws_addr"));
				dc.setSubsCode(rs.getString("subs_code"));
				dc.setAppType(rs.getString("app_type"));
				dc.setNsUri(rs.getString("NS_URI"));
				dc.setRemark(rs.getString("remark"));
				dc.setValidDate(rs.getString("valid_date"));
				dc.setInvalidDate(rs.getString("invalid_date"));
				dc.setLastModifyDate(rs.getString("last_modify_date"));
			}
		} catch (SQLException e) {
			throw new SQLException("queryPluginWebappConfWithKeys is Wrong!"
					+ e.getMessage());
		} finally {
			close(rs, null, ps);
		}
		return dc;
	}

	/**
	 * 根据查询条件查询多条或单条记录
	 * @param szCondition 
	 * @return
	 * @throws SQLException
	 */
	public List<PluginWebappConf> queryPluginWebappConfWithCond(String szCondition,String szOrderBy)
			throws SQLException {
		List<PluginWebappConf> dcList = new ArrayList<PluginWebappConf>();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement("SELECT * FROM urps.plugin_webapp_conf "
					+ szCondition + " " + szOrderBy + " with ur");
			rs = ps.executeQuery();
			while (rs.next()) {
				PluginWebappConf dc = new PluginWebappConf();
				dc.setPluginConfId(rs.getString("plugin_conf_id"));
				dc.setConfSort(rs.getInt("conf_sort"));
				dc.setWsAddr(rs.getString("ws_addr"));
				dc.setSubsCode(rs.getString("subs_code"));
				dc.setAppType(rs.getString("app_type"));
				dc.setNsUri(rs.getString("NS_URI"));
				dc.setRemark(rs.getString("remark"));
				dc.setValidDate(rs.getString("valid_date"));
				dc.setInvalidDate(rs.getString("invalid_date"));
				dc.setLastModifyDate(rs.getString("last_modify_date"));
				dcList.add(dc);
			}
		} catch (SQLException e) {
			throw new SQLException("queryPluginWebappConfWithCond is Wrong!"
					+ e.getMessage());
		} finally {
			close(rs, null, ps);
		}
		return dcList;
	}

	/**
	 * 关闭资源
	 * @param theRs
	 * @param theStmt
	 * @param thePs
	 */
	protected void close(ResultSet theRs, Statement theStmt,
			PreparedStatement thePs) {
		try {
			if (theRs != null)
				theRs.close();
			if (theStmt != null)
				theStmt.close();
			if (thePs != null)
				thePs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
